using System;
using AutoMapper;
using MovieDB.Models;

namespace MovieDB.Mapping.CustomConverter
{
    public class MovieDtoCreatedAtResolver : ValueResolver<MovieModel, DateTime>
    {
        protected override DateTime ResolveCore(MovieModel source)
        {
            DateTime cratedAsDate;
            if (!DateTime.TryParse(source.CreatedAt, out cratedAsDate))
            {
                cratedAsDate = DateTime.UtcNow;
            }
            return cratedAsDate;
        }
    }
}